package com.sn.controller;

import com.sn.controller.header.CommonHeader;
import com.sn.core.http.CommRequest;
import com.sn.core.http.CommResult;
import com.sn.core.util.pub.exception.ServiceException;
import com.sn.core.util.pub.tool.ResponseTools;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 */
public abstract class BaseController {

    protected CommonHeader reduceHeader;

    protected CommRequest<Object> query;


    public CommResult responseJson(Object o) {
        return ResponseTools.get().response(o);
    }


    @ExceptionHandler(ServiceException.class)
    public void handleServiceException(HttpServletRequest request, HttpServletResponse response, Exception ex) {
        ex.printStackTrace();
        ResponseTools.get().responseErrResult(response, ex);
    }

    @ExceptionHandler(Exception.class)
    public void handleException(HttpServletRequest request, HttpServletResponse response, Exception ex) {
        ex.printStackTrace();
        ResponseTools.get().responseErrResult(response, ex);
    }
}
